from app1.database import db_session
from flask import Flask, render_template, request, redirect, url_for, session

app = Flask(__name__)

# app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///students.sqlite3'


@app.route('/<name>')
def hello(name="World"):
    return 'Hello %s!' % name


@app.route('/hello/<name>')
def hello_world(name):
    return "hello244 %s" % name


@app.route('/url')
def url1():
    # return "hello244"
    return redirect(url_for('hello', name="uuu"))


@app.route('/success/<name>')
def success(name):
    return 'welcome %s' % name


@app.route('/login', methods=['POST', 'GET'])
def login():
    if request.method == 'POST':
        user = request.form['nm']
        return redirect(url_for('success', name=user))
    else:
        user = request.args.get('nm')
        return redirect(url_for('success', name=user))


@app.route('/login1')
def index():
    return render_template("login.html")


@app.route('/result')
def result():
    ddd = {'phy': 50, 'che': 60, 'maths': 70}

    return render_template('result.html', result=ddd)


@app.route('/http')
def http1():

    return "%s <br/> %s<br/> %s<br/> %s" % (request.method, request.form, request.cookies, session)


@app.teardown_appcontext
def shutdown_session(exception=None):
    db_session.remove()


if __name__ == '__main__':
    app.run(debug=True)
